<?php

namespace App\Models\ModelManage;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Table
 * @package App\Models\ModelManage
 * @version August 7, 2018, 5:45 pm CST
 *
 * @property string name
 * @property string title
 * @property string type
 * @property string description
 */
class Table extends Model
{
    use SoftDeletes;

    public $table = 'tables';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'title',
        'type',
        'description',
        'database_id',
        'relation', // 关系
        'clone', // 克隆
        'publish', // 发布
        'listorder', // 排序
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'        => 'string',
        'title'       => 'string',
        'type'        => 'string',
        'description' => 'string',
        'relation'    => 'string',
        'clone'       => 'string',
        'publish'     => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name' => 'required|max:100',
    ];

    /**
     * 表字段
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function tablefields()
    {
        return $this->hasMany(\App\Models\ModelManage\TableField::class, 'table_id', 'id');
    }

    /**
     * 数据库
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function database()
    {
        return $this->hasOne(\App\Models\ModelManage\Database::class, 'id', 'database_id');
    }


}
